//
//  Const.swift
//  jiaoyi
//
//  Created by wjk on 2018/8/8.
//  Copyright © 2018年 wjk. All rights reserved.
//

import Foundation
import UIKit
import KRProgressHUD
import Toast
import Kingfisher
import MJRefresh
import SwiftyJSON

func kRGBColorFromHex(rgbValue: Int) -> (UIColor) {
    
    return UIColor(red: ((CGFloat)((rgbValue & 0xFF0000) >> 16)) / 255.0,
                   green: ((CGFloat)((rgbValue & 0xFF00) >> 8)) / 255.0,
                   blue: ((CGFloat)(rgbValue & 0xFF)) / 255.0,
                   alpha: 1.0)
}
func imageFromColor(color: UIColor, viewSize: CGSize) -> UIImage{
    
    let rect: CGRect = CGRect(x: 0, y: 0, width: viewSize.width, height: viewSize.height)
    
    UIGraphicsBeginImageContext(rect.size)
    
    let context: CGContext = UIGraphicsGetCurrentContext()!
    
    context.setFillColor(color.cgColor)
    
    context.fill(rect)
    
    
    
    let image = UIGraphicsGetImageFromCurrentImageContext()
    
    UIGraphicsGetCurrentContext()
    
    return image!
    
}

//圆角
func viewRadius(cor:CGFloat, img:UIView) ->Void {
    img.clipsToBounds = true
    img.layer.cornerRadius = cor    
    img.layer.borderWidth = 0
}
//边框
func viewBorderRadius(cor:CGFloat, img:UIView, with:CGFloat,color:UIColor) ->Void {
    img.clipsToBounds = true
    img.layer.cornerRadius = cor
    img.layer.borderColor = color.cgColor
    img.layer.borderWidth = with
}

func showMessage(message:String) -> Void {
    UIApplication.shared.delegate?.window??.makeToast(message)
}
func showMessage(view:UIView, message:String) -> Void {
    view.makeToast(message)
}


func imageUrl(img:UIImageView,url:String) -> Void {
    img.kf.setImage(with: ImageResource.init(downloadURL: URL.init(string: url)!))
}
func showHUD() -> Void{
    KRProgressHUD.show()
}

func dismissHUD() ->  Void{
    KRProgressHUD.dismiss()
}

func jsonFormater(data:Any) -> JSON {
    return JSON(data)
}

func tableviewBackgroundColor() -> UIColor {
    return kRGBColorFromHex(rgbValue: 0xEBEBF1)
}

func baseColor() -> UIColor {
    return kRGBColorFromHex(rgbValue: 0x50a4f9)
}
func deviceHight() -> CGFloat {
    return UIScreen.main.bounds.height
}
func deviceWidth() -> CGFloat {
    return UIScreen.main.bounds.width
}


